﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Guide
{
    public partial class Stock : System.Web.UI.UserControl
    {

        private List<Province> _listProvince;

        public List<Province> ListProvince
        {
            get { return _listProvince; }
            set { _listProvince = value; }
        }

        public string LabelContext
        {
            get { return Label1.Text; }
            set { Label1.Text = value; }
        }

        public GridView GridView
        {
            get { return this.GridView1; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//放到if (!IsPostBack) 里面
            {
                doDataBound();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        public void getTheData(out string Name, out List<string> list)
        {

            Name = this.Label1.Text;
            StringBuilder sb = new StringBuilder();
            GridView1.AllowPaging = false;
            GridView1.DataBind();
            List<string> listProvinceName = new List<string>();
            foreach (GridViewRow row in this.GridView1.Rows)
            {

                bool isChecked = false;
                if ((row.FindControl("CheckBox1") as CheckBox).Checked == true)
                {
                    isChecked = true;
                }
                else
                {
                    isChecked = false;
                }

                if (isChecked)
                {
                    listProvinceName.Add((row.FindControl("ProvinceCName") as Label).Text);
                }
            }

            GridView1.AllowPaging = true;
            GridView1.DataBind();
            list = listProvinceName;

        }



        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            // Cancel the paging operation if the user attempts to navigate
            // to another page while the GridView control is in edit mode. 
            if (GridView1.EditIndex != -1)
            {
                // Use the Cancel property to cancel the paging operation.
                e.Cancel = true;

                // Display an error message.
                int newPageNumber = e.NewPageIndex + 1;

                GridView1.PageIndex = e.NewPageIndex;
                doDataBound();
                //Message.Text = "Please update the record before moving to page " +
                //  newPageNumber.ToString() + ".";
            }
            else
            {
                // Clear the error message.
                //Message.Text = "";
            }

            GridView1.PageIndex = e.NewPageIndex;
            doDataBound();

        }

        private void doDataBound()
        {
            this.GridView1.DataSource = _listProvince;
            this.GridView1.DataBind();
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            this.GridView.Visible = false;
        }
    }
}